var utils = require("../utils/utils");
var app_utils = require("../utils/app_utils");
var files_logger = require("../utils/files_logger");
var read = require("./taskRead");
var treasure = require("./taskTreasure");
var search_30 = require("./taskSearch30");
var search_2 = require("./taskSearch2");
var APP_CONST_NAME = "闪电搜索";
var main = {
  exec_times: 0,
  last_run_time: null,
  is_over: false,
  run() {
    var result = app_utils.openApp(APP_CONST_NAME);
    if (!result) {
      console.log("没有安装--闪电搜索--，跳过本次任务");
      return;
    } else {
      files_logger.app_start_logger("闪电搜索");
    }
    this.last_run_time = Date.now();
    this.exec_times = this.exec_times + 1;

    sleep(utils.get_random_interval(6, 0, 2, 1000));

    var tasks = [
      //read,
      treasure,
      search_2,
      search_30,
    ];
    for (var index = 0; index < tasks.length; index++) {
      var task = tasks[index];
      task.go_page_from_home();
      if (utils.exists_text_starts_with("明天再来")) {
        this.is_over = true;
        console.log("闪电搜索 main: 找到--明天再来--");
      }
      sleep(utils.get_random_interval(2, 0, 1, 1000));
    }
    app_utils.close();
    console.log("闪电搜索 main: 执行完成本轮任务");
    var content =
      "闪电搜索,本次运行耗时：" +
      ((Date.now() - this.last_run_time) / 1000).toFixed(2) +
      "s,大约" +
      ((Date.now() - this.last_run_time) / 1000 / 60).toFixed(2) +
      "分钟。今天已经运行-" +
      this.exec_times +
      "-次!\n";
    files_logger.app_start_logger("闪电搜索", content);
    sleep(utils.get_random_interval(2, 0, 1, 1000));
  },
};
main.run();
